package com.lm.security.core.validate.code;

import com.lm.security.core.properties.SecurityProperties;
import com.lm.security.core.validate.code.sms.DefaultSmsCodeSender;
import com.lm.security.core.validate.code.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lm_jcf
 * @date 2018/5/3 9:55
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private SecurityProperties securityProperties;

    @Bean
    @ConditionalOnMissingBean(name = "imageCodeGenerator")      //表示容器初始化时先去找容器里是否有相应name的bean对象，如果有则不生成此方法的bean，反之生成
    public ValidateCodeGenerator imageCodeGenerator(){
        ImageCodeGenerator imageCodeGenerator = new ImageCodeGenerator();
        imageCodeGenerator.setSecurityProperties(securityProperties);
        return imageCodeGenerator;
    }

    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)      //表示容器初始化时先去找容器里是否有相应name的bean对象，如果有则不生成此方法的bean，反之生成
    public SmsCodeSender smsCodeSender(){
        return new DefaultSmsCodeSender();
    }
}
